package ua.in.iticket.addressbook.person;

import org.apache.commons.lang.builder.ToStringBuilder;

/**
 * Created by ivanov-av
 * 05.02.14 15:31.
 */
public class PhoneNumber {
    protected String countryCode; // код страны
    protected String operatorCode; // код оператора
    protected String number; // сам номер
    protected String note; // примечание

    public PhoneNumber(String countryCode, String operatorCode, String number, String note) {
        this.countryCode = countryCode;
        this.operatorCode = operatorCode;
        this.number = number;
        this.note = note;
    }

    public String getCountryCode() {
        return countryCode;
    }

    public String getOperatorCode() {
        return operatorCode;
    }

    public String getNumber() {
        return number;
    }

    public String getNote() {
        return note;
    }

    public PhoneNumber(String countryCode, String operatorCode, String number) {
        this.countryCode = countryCode;
        this.operatorCode = operatorCode;
        this.number = number;
    }

    public PhoneNumber() {
    }

    public String getFullNumber(){
        return this.countryCode +"-" + this.operatorCode + "-" + this.number + (this.note != null ? " Примечание: " + this.note : "");
    }

    public String getShortNumber(){
        return this.countryCode +"-" + this.operatorCode + "-" + this.number;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj) return true;

        if (!( obj instanceof PhoneNumber)) return false;
        PhoneNumber that = (PhoneNumber) obj;

        if ( countryCode != null ? !countryCode.equals(that.countryCode) : that.countryCode != null) return false;
        if ( operatorCode != null ? !operatorCode.equals(that.operatorCode) : that.operatorCode != null) return false;
        if ( number != null ? !number.equals(that.number) : that.number != null) return false;
        return true;
    }

    @Override
    public int hashCode() {
        return this.countryCode.hashCode() + this.operatorCode.hashCode() + this.number.hashCode();
    }

    @Override
    public String toString() {
        return new ToStringBuilder(this)
                .appendSuper (super.toString())
                .append("countryCode", countryCode)
                .append("operatorCode", operatorCode)
                .append("number", number)
                .append("note", note)
                .toString();
    }
}
